/**
 * 
 */
package smallChanges.statements;

import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
import net.sourceforge.pmd.ast.ASTPrimitiveType;
import net.sourceforge.pmd.ast.ASTReferenceType;
import net.sourceforge.pmd.ast.ASTType;
import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
import smallChanges.Tokenization.TokenSet;
import smallChanges.util.SCConstants;

/**
 * @author jspacco
 *
 */
public class TypeVisitor extends JavaParserVisitorAdapter implements SCConstants 
{
	private TokenSet tokenSet;
    
    public TypeVisitor(TokenSet tokenSet) {
        this.tokenSet=tokenSet;
    }

	/* (non-Javadoc)
	 * @see net.sourceforge.pmd.ast.JavaParserVisitorAdapter#visit(net.sourceforge.pmd.ast.ASTPrimitiveType, java.lang.Object)
	 */
	@Override
	public Object visit(ASTPrimitiveType node, Object data)
	{
		SCType sctype=(SCType)data;
		if (sctype.isArrayType()) {
			// Arrays are:
			// ASTReferenceType(array) => ASTPrimitive
			// or
			// ASTReferenceType(array) => ASTClassOrInterfaceType
			sctype.setType(node.getImage());
		} else {
			sctype.setKind(PRIMITIVE);
			sctype.setArrayType(node.isArray());
			sctype.setType(node.getImage());
		}
		return super.visit(node, data);
	}

	/* (non-Javadoc)
	 * @see net.sourceforge.pmd.ast.JavaParserVisitorAdapter#visit(net.sourceforge.pmd.ast.ASTReferenceType, java.lang.Object)
	 */
	@Override
	public Object visit(ASTReferenceType node, Object data)
	{
		SCType sctype=(SCType)data;
		
		sctype.setKind(REFERENCE);
		sctype.setArrayType(node.isArray());
		
		return super.visit(node, data);
	}

	/* (non-Javadoc)
	 * @see net.sourceforge.pmd.ast.JavaParserVisitorAdapter#visit(net.sourceforge.pmd.ast.ASTClassOrInterfaceType, java.lang.Object)
	 */
	@Override
	public Object visit(ASTClassOrInterfaceType node, Object data)
	{
		if (data instanceof SCType) {
			SCType sctype=(SCType)data;
			sctype.setType(node.getImage());
		}
		return super.visit(node, data);
	}

    @Override
    public Object visit(ASTType node, Object data)
    {
        if (data instanceof SCType) {
            SCType type=(SCType)data;
            type.setCoordinatesFromNode(node);
        }
        return super.visit(node, data);
    }
	
	
	
	
}
